import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

export const postsApi = createApi({
  reducerPath: "postsApi",
  baseQuery: fetchBaseQuery({
    baseUrl: "http://jsonplaceholder.typicode.com/posts",
  }),
  endpoints: (builder) => ({
    getPost: builder.query({
      query: (id) => `?userId=${id}`,
    }),

    getComments: builder.query({
      query: (postId) => `/${postId}/comments`
    })
  }),
});

export const { useGetPostQuery, useLazyGetCommentsQuery} = postsApi;
